home *** CD-ROM | disk | FTP | other *** search
- Path: usenet.ggu.edu!user
- From: elaw@usenet.ggu.edu (Elaine Law)
- Newsgroups: comp.lang.c
- Subject: Re(2): Finding a prime number
- Date: Sun, 11 Feb 96 23:20:51 -0800
- Organization: ggu.edu
- Message-ID: <1844965.ensmtp@usenet.ggu.edu>
- NNTP-Posting-Host: usenet.ggu.edu
- X-Newsreader: ExpressNet/SMTP v1.1.5
-
- Give this a try.
-
- #include<stdio.h>
- #include<conio.h>
- void main(void)
- {
- long inp=0, ctr=0;
- int total=0, ctr2=0;
- clrscr();
- do { printf("Enter a number from 1 to 1000000: ");
- scanf("%d", &inp);
- } while (inp<1 || inp>1000000);
- printf("\nThe prime numbers are:\n ");
- for (ctr=1; ctr<=inp; ctr++)
- { for (total=0, ctr2=1; ctr2<ctr; ctr2++)
- { if (ctr%ctr2==0)
- { total++; }
- }
- if (total<2)
- { printf("%d\t", ctr); }
- }
- }
- ===========
- and lo, there was much rejoicing among the people, as
- kannan@emirates.net.ae (Kannan) writes:
-
- >Is it not easy to just check whether the integer is divisible by 2 or
- >3 and decide (except 1 & 3 which is a prime number)? For ex., 723232
- >this would be divisible by 2 so not a prime number. And 997 cannot be
- >divided by these 2. This is prime number. Please correct me if I am
- >wrong without attacking me personally :)
-
- 35/2 = 17.5_
- 35/3 = 11.66
-
- therefore, 35 is prime.
-
- .hymie
- hymie@lactose.smart.net
- self-appointed chairman of the 3-man keep-the-browns-in-cleveland foundation
- GCS/M d-(--) s: a25 C++ UL++ P+ E- W++ N+++ w--- M- PS+ PGP+ Y+ t+/* tv+ DI++
- b+ G+ h- e++/* r++ y+ pgp key at web page
- http://www.smart.net/~hymowitz/
- ===============================================================================
-
- sorry, this .sig is not a winner. remember to check the .sig every time
- you read a hymie! brand post or letter. please try again. good luck!
- ===============================================================================
-
-
-
-